home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boref.arc / BOREF2.PAS < prev   
Pascal/Delphi Source File  |  1985-11-17  |  21KB  |  733 lines

  1. .R:
  2. .R:
  3. .X:8
  4. .XT:4
  5. .F:
  6. .F:
  7. .F:Boosters Users Guide...Page $$$...
  8.                                NSORBIT
  9.  
  10.  
  11. Declaration: Procedure NsOrbit ( X1 : ColumnType;
  12.                                  Y1 : RowType;
  13.                                  X2 : ColumnType;
  14.                                  Y2 : RowType;
  15.                               Style : Integer;
  16.                     NumberOfSeconds : Integer);
  17.  
  18. Purpose:     Draws a box at X1,Y1,X2,Y2 in selected Style, then      
  19.              erases all but two components of the box, which ì
  20.              orbit the box interior for time NumberOfSeconds.
  21.              After orbiting, NsOrbit redraws the original box.
  22.  
  23.  
  24.              Notes:
  25.              1.  Style is a value from 1 to 4 and controls theì
  26.                  number of lines in a box side (see Boxul ì
  27.                  description for details).
  28.  
  29.  
  30. Example:     Display 60 boxes and select one at random to orbit.
  31.  
  32.              (*$IBodecl  *)
  33.              (*$IPutStr  *)
  34.              (*$ICopies  *)
  35.              (*$IBoxul   *)
  36.              (*$ISetAtt  *)
  37.              (*$ITimer   *)
  38.              (*$INsOrbit *)
  39.              var
  40.                 Ulx, Uly : Integer;
  41.  
  42.              BEGIN
  43.  
  44.                 ClrScr;
  45.                 for i := 1 to 15 do
  46.                 begin
  47.                    Boxul (1+(i-1)*4,1,4+(i-1)*4,4,1,14);
  48.                    Boxul (1+(i-1)*4,6,4+(i-1)*4,9,2,14);
  49.                    Boxul (1+(i-1)*4,11,4+(i-1)*4,14,3,14);
  50.                    Boxul (1+(i-1)*4,16,4+(i-1)*4,19,4,14);
  51.                 end;
  52.                 PutStr (h,'Press enter to orbit',60,25,14);
  53.                 read;
  54.                 Randomize;
  55.                 Ulx := Random(15);
  56.                 Uly := Random( 4);
  57.                 NsOrbit (1+Ulx*4, 1+Uly*5, 4+Ulx*4, 4+Uly*5, Uly+1, 4);
  58.  
  59.              END (* XNsOrbit *) .
  60. 
  61.                                OVERSTR
  62.  
  63.  
  64. Declaration: Function OverStr ( New, Target : AnyString;
  65.                                 Pos, Len    : Integer;
  66.                                 Pad         : Char) : AnyString;
  67.  
  68.  
  69. Purpose:     Overlays New onto Target beginning at Pos, for ì
  70.              length Len, then pads or truncates accordingly.
  71.  
  72.  
  73.              Notes:
  74.              1.  Padding occurs when Pos > length(Target) orì
  75.                  LEN > length(New).
  76.  
  77.  
  78. Example:     Modify and pad a string. 
  79.  
  80.              (*$IBodecl  *)
  81.              (*$IOverStr *)
  82.              (*$IPutStr  *)
  83.  
  84.              BEGIN
  85.                 ClrScr;
  86.                 S := 'Change this field '+#220+#223+#220+#223+
  87.                      #220+#223+' to an alternate pattern, '+
  88.                      'pad to end of line.';
  89.                 PutStr (h,S,1,1,14);
  90.                 read;
  91.                 PutStr (h,OverStr (#223+#220+#223+#220+#223+#220,
  92.                                    S,19,61,#223),1,1,14);
  93.  
  94.              END (* XOverStr *) .
  95. 
  96.                                 PUTSTR
  97.  
  98.  
  99. Declaration: Procedure PutStr ( HV : Char;
  100.                                  S : AnyString;
  101.                                  X : ColumnType;
  102.                                  Y : RowType;
  103.                                Att : Integer);
  104.  
  105.  
  106. Purpose:     Writes S to video display beginning at X,Y, with ì
  107.              display attribute Att.
  108.   
  109.              Notes:ì
  110.              1.  If HV  = 'V', direction of write is vertical.  Ifì
  111.              HV is any other character, direction of write is ì
  112.              horizontal.  
  113.              2.  PutHeap is the corresponding Heap I/O routine.
  114.  
  115.  
  116. Example:     Create screens using Write, PutStr, and Heap I/O.
  117.  
  118.              (*$IBoDecl   *)
  119.              (*$IPutStr   *)
  120.              (*$ICenter   *)
  121.              (*$ISaves    *)
  122.              (*$IRestores *)
  123.              (*$IPutHeap  *)
  124.  
  125.              BEGIN
  126.  
  127.                 Mark ( HeapTop );
  128.                 New ( page[1] );
  129.                 ClrScr;
  130.                 for i := 1 to 25 do
  131.                    writeln('Using Orthodox methods of screen I/O');
  132.                 SaveScreen ( page[1] );
  133.                 read;
  134.                 for i := 1 to 25 do
  135.                    PutStr (h,Center(' Using PutStr with Center function ',
  136.                            40,' '),41,i,112);
  137.                read;
  138.                ClrScr;
  139.                read;
  140.                for i := 1 to 25 do
  141.                   PutHeap ( page[1], h,Center(' Used PutHeap and'+
  142.                           ' RestoreScreen ',40,' '),41,i,112);
  143.                RestoreScreen ( page[1] );
  144.                Release ( HeapTop );
  145.  
  146.             END (* XPutStr *) .
  147. 
  148.                                 REMBLK
  149.  
  150.  
  151. Declaration: Procedure RemBlk ( X1 : ColumnType;
  152.                                 Y1 : RowType;
  153.                                 X2 : ColumnType;
  154.                                 Y2 : RowType);
  155.  
  156.  
  157. Purpose:     Removes the block at display location 
  158.              X1,Y1,X2,Y2 by filling it with blanks.
  159.  
  160.              Notes:
  161.              1.  The attribute byte of the blanked area is 
  162.                  set to 14 (intense yellow).
  163.              2.  Use FillHeap to remove areas of the heap.
  164.  
  165.  
  166. Example:     Fill the screen with alternate ones and zeroes, then ì
  167.              remove the zeroes.
  168.  
  169.              (*$IBoDecl *)
  170.              (*$IRemBlk *)
  171.              (*$IPutStr *)
  172.  
  173.              var  j : integer;
  174.  
  175.              BEGIN
  176.  
  177.                 repeat
  178.                    for i := 1 to 25 do
  179.                       for j := 1 to 8 do
  180.                          PutStr (h,'1010101010',1+(j-1)*10,i,14);
  181.                    read(Kbd,ch);
  182.                    for j := 1 to 40 do
  183.                       RemBlk (2+(j-1)*2,1,2+(j-1)*2,25);
  184.                    read(Kbd,ch);
  185.                 until ch = ' ';
  186.  
  187.              END (* XRemBlk *) .
  188. 
  189.                                  RIGHT
  190.  
  191.  
  192. Declaration: Function Right ( S : AnyString;
  193.                             Len : Integer;
  194.                             Pad : Char): AnyString;    
  195.  
  196.  
  197. Purpose:     Returns S right-justified in a string of length Len,  
  198.              padded or truncated on the left as needed.
  199.  
  200.  
  201. Example:     Use right function to decimal-align monetary values.
  202.  
  203.              (*$IBoDecl *)
  204.              (*$IRight  *)
  205.              (*$IPutStr *)
  206.  
  207.              BEGIN
  208.  
  209.                 ClrScr;
  210.                 PutStr (h,Right ('0.12',12,' '),1,2,14);
  211.                 PutStr (h,Right ('77,126.99',12,' '),1,3,14);
  212.                 PutStr (h,Right ('1,345,200.06',12,' '),1,4,14);
  213.                 PutStr (h,Right ('35.00',12,' '),1,5,14);
  214.  
  215.              END (* XRight *) .
  216. 
  217.                                  RWORD
  218.  
  219.  
  220.  
  221. Declaration: Function Rword (  S : AnyString;
  222.                                N : Integer;
  223.                               St : AnyString ) : AnyString;
  224.  
  225.  
  226. Purpose:     Replace word N of S with St.  All other words of
  227.              S (if any) remain unaffected.  
  228.  
  229.  
  230.              Notes:
  231.  
  232.              1.  A word is any blank-delimited sequence of
  233.                  characters or a string of nonblank characters.
  234.  
  235.              2.  If Length(Rword( S,N,St )) > 255, then St is
  236.                  reduced to fit.
  237.  
  238.  
  239. Example:     Replace the day of the week with the date.
  240.  
  241.  
  242.              Given:  S := 'Today is Friday';
  243.  
  244.              Then:   S := Rword ( S, 3, 'November 15, 1985');
  245.  
  246.              Yields: S := 'Today is November 15, 1985';
  247.  
  248.  
  249.              Note:
  250.  
  251.              1.  For a working routine using Rword and other
  252.                  word functions, see the example for Words.
  253. 
  254.                   SAVE AND RESTORE SCREEN PROCEDURES
  255.  
  256.  
  257. Declaration: Procedure SaveScreen    ( Page : HeapBuf );
  258.              Procedure RestoreScreen ( Page : HeapBuf );
  259.  
  260.  
  261. Purpose:     Provide convenience and speed for saving and 
  262.              restoring contents of video display.  
  263.  
  264.              Notes:
  265.              1.  See BoDemo for additional examples
  266.                  of SaveScreen and RestoreScreen.
  267.  
  268. Example:     Create two screens, saving each, then alternately
  269.              restore them under user control.
  270.  
  271.              (*$IBoDecl *)
  272.              (*$ICopies *)
  273.              (*$ICenter *)
  274.              (*$IPutStr *)
  275.              (*$ISaves  *)
  276.              (*$IRestores *)
  277.  
  278.              BEGIN
  279.  
  280.                 Mark ( HeapTop );
  281.                 New  ( page[1] );
  282.                 New  ( page[2] );
  283.  
  284.                 for i := 1 to 25 do
  285.                    PutStr (h,Copies ( ' ' ,80), 1, i, 7 );
  286.                 PutStr (h, Center (' PRESS ANY KEY ',80,' ' ),1,13,7);
  287.                 SaveScreen ( page[1] );
  288.                 read(Kbd,ch);
  289.                 for i := 1 to 25 do
  290.                    PutStr (h,Center ( 'This is screen 2 - ' +
  291.                                       'press SpaceBar to quit',
  292.                                        80,' '),1,i,14);
  293.                 SaveScreen ( page[2] );
  294.                 read(Kbd,ch);
  295.                 repeat
  296.                    RestoreScreen ( page[1] );
  297.                    read(Kbd,ch);
  298.                    RestoreScreen ( page[2] );
  299.                    read(Kbd,ch);
  300.                 until ch = ' ';
  301.                 Release ( HeapTop );
  302.  
  303.              END (* XScreen *) .
  304.                                 SETATT 
  305.  
  306.  
  307. Declaration: Procedure SetAtt ( X1 : ColumnType;
  308.                                 Y1 : RowType;
  309.                                 X2 : ColumnType;
  310.                                 Y2 : RowType;
  311.                                Att : Integer);
  312.  
  313.  
  314. Purpose:     Sets the video attributes of the block defined by 
  315.              X1,Y1,X2,Y2 according to the value of Att.
  316.  
  317.              Notes:
  318.              1.  HeapAt sets attributes for pages on the heap.
  319.  
  320.  
  321. Example:     Draw 20 bars, then allow the user to set their ì
  322.              attributes.
  323.  
  324.              (*$IBoDecl *)
  325.              (*$ISetAtt *)
  326.              (*$IPutStr *)
  327.  
  328.              var
  329.                 j, Att : integer;
  330.      
  331.              BEGIN
  332.  
  333.                 ClrScr;
  334.                 for i := 1 to 6 do
  335.                    for j := 1 to 20 do
  336.                       PutStr (h,#04 +#04 +#04 , 1+(j-1)*4, 7-i, 14);
  337.  
  338.                 repeat
  339.                    PutStr (h, 'Enter attribute value,'+
  340.                          ' 0-255 (Out of Range quits) ',
  341.                            1,10,14);
  342.                    ClrEol;
  343.                    read(att);
  344.                    if (att >= 0) and (att <= 255) then
  345.                       for i := 1 to 20 do
  346.                          SetAtt (1+(i-1)*4,1,3+(i-1)*4,6,att);
  347.                 until (att < 0) or (att > 255);
  348.  
  349.              END (* XSetatt *) .
  350. 
  351.                                  SPACE
  352.  
  353.  
  354. Declaration: Function Space ( S : AnyString ) : AnyString;
  355.  
  356.  
  357. Purpose:     Returns a string that is S normalized.  A 
  358.              normalized string has no leading or trailing
  359.              blanks and one blank between each word.
  360.  
  361.  
  362.              Notes:
  363.  
  364.              1.  A word is any blank-delimited sequence of 
  365.                  characters or a string of nonblank characters.
  366.  
  367.  
  368. Example:     Normalize a string.
  369.  
  370.  
  371.              Given:   S := '   X   Y   Z   ';
  372.  
  373.              Then:    S := Space ( S );
  374.  
  375.              Yields:  S := 'X Y Z';
  376.  
  377.  
  378.              Note:
  379.  
  380.              1.  For a working routine using Space and other
  381.                  word functions, see the example for Words.
  382. 
  383.                                  STRIP
  384.  
  385.  
  386. Declaration: Function Strip ( S : AnyString;
  387.                               C : Char) : AnyString;
  388.  
  389.  
  390. Purpose:     Copies S to the result string, excluding leading      ì
  391.              and trailing C characters. 
  392.  
  393.  
  394. Example:     Isolate the dollar sign.
  395.  
  396.              (*$IBoDecl *)
  397.              (*$IStrip  *)
  398.              (*$IPutStr *)
  399.  
  400.              BEGIN
  401.  
  402.                 ClrScr;
  403.                 S := '   111222333444$444333222111   ';
  404.                 PutStr (h, s, 1,1,14);
  405.                 read;
  406.                 PutStr (h, strip (strip ( strip ( strip (strip   
  407.                 (S,' ') ,'1'),'2'),'3'),'4'),1,2,14);
  408.  
  409.              END (* Xstrip *) . 
  410. 
  411.                                   TIMER
  412.  
  413.  
  414. Declaration: Function Timer (Seconds : Integer ) : Boolean;ì
  415.                     ì
  416.  
  417. Purpose:     Returns TRUE if Seconds seconds have elapsed since   ì
  418.              Timer's invocation.
  419.  
  420.              Notes:
  421.              1.  StartElapsed and TimeElapsed arσ globals. ì
  422.                  StartElapsed must be initialized to FALSE.  Both ì
  423.                  are part of BoDecl (Boosters Declarations file). ì
  424.  
  425.              2.  Timer uses the system clock (seconds value) to ì
  426.                  keep track of the time elapsed.  The hundredth ì
  427.                  value of the clock is set to zero when the ì
  428.                  timing begins, to ensure a full initial second.ì
  429.  
  430.              3.  Calls to Timer should not be nested.
  431.  
  432.              4.  See the Wait procedure for an illustration
  433.                  of how to use Timer.
  434.  
  435. Example:     Demonstrate a five-second timing.
  436.  
  437.              var
  438.                 SaveTime : integer;
  439.  
  440.              (*$IBoDecl *)
  441.              (*$ITimer  *)
  442.              (*$IPutStr *)
  443.  
  444.              BEGIN
  445.  
  446.                 ClrScr;
  447.                 PutStr (h,'Set timer for 5 seconds. . .',30,6,14);
  448.                 i := 5;
  449.                 SaveTime := TimeElapsed;
  450.                 repeat
  451.                    if TimeElapsed <> SaveTime then
  452.                    begin
  453.                       str (i,s);
  454.                       PutStr (h,s, 40,12-i,14);
  455.                       i := i - 1;
  456.                       SaveTime := TimeElapsed;
  457.                    end;
  458.                 until Timer(5);
  459.                 PutStr (h,'Time''s up.',37,13,14);
  460.                 read;
  461.      
  462.              END (* Xtimer *) .
  463. 
  464.                        SET AND DISPLAY SYSTEM TIME
  465.  
  466.  
  467. Declaration: Procedure TimeXY ( X : ColumnType; Y : RowType);
  468.  
  469.              Procedure Stime  ( hh, mm, ss : integer );
  470.  
  471.  
  472. Purpose:     TimeXY displays the system time, while Stime sets it.
  473.  
  474.  
  475. Example:     Allow user to set time while current time continually
  476.              displays.
  477.  
  478.              (*$IBoDecl *)
  479.              (*$IPutStr *)
  480.              (*$ITimeXY *)
  481.              (*$IStime  *)
  482.  
  483.              var  hh, mm, ss : integer;
  484.  
  485.              function Range ( Ch: Char): boolean;
  486.              begin
  487.                 case Ch of
  488.                    #32,#48..#57 : Range := True
  489.                 else
  490.                    Range := false;
  491.                 end;
  492.              end;
  493.  
  494.              BEGIN
  495.  
  496.                 ClrScr;
  497.                 S := '';
  498.                 PutStr ( h,'Current time: ',30,1, 14 );
  499.                 PutStr ( h, 'Enter new time exactly as shown',1, 9, 14);
  500.                 PutStr ( h, '      HH MM SS: ',1,10, 14);
  501.                 SaveX := 17;
  502.                 SaveY := 10;
  503.                 Repeat
  504.                    repeat
  505.                       TimeXY(44,1);
  506.                       GoToXY(SaveX,SaveY);
  507.                    until KeyPressed;
  508.                    read(Kbd,ch);
  509.                    if Range(ch) then
  510.                    begin
  511.                       S := S + ch;
  512.                       write(Ch);
  513.                       SaveX := WhereX;
  514.                    end;
  515.                 until Ch = #13;
  516.                 val ( Copy(S,1,2),hh,ecode );
  517.                 val ( Copy(S,4,2),mm,ecode );
  518.                 val ( Copy(S,7,2),ss,ecode );
  519.                 Stime ( hh,mm,ss );
  520.                 repeat TimeXY(44,1) until KeyPressed;
  521.  
  522.              END (* XtimeXY *) .
  523. 
  524.                                  UPPER
  525.  
  526.  
  527. Declaration: Function Upper ( S : AnyString) : AnyString;
  528.  
  529.  
  530. Purpose:     Provides uppercase translation as a function call.
  531.              Returns a string with all lowercase alphabeticsì
  532.              converted to uppercase.
  533.  
  534.  
  535.              Notes: 
  536.              1.  For a technique using a procedure call, see the ì
  537.                  Turbo Pascal manual.
  538.  
  539.  
  540. Example:     Translate user input to uppercase.
  541.  
  542.              (*$IBoDecl *)
  543.              (*$IUpper  *)
  544.              (*$ICenter *)
  545.  
  546.              BEGIN
  547.  
  548.                 ClrScr;
  549.                 Write ( Center ('Enter any string '+
  550.                       '(''quit'' quits)',80,' '));
  551.                 window(1,2,80,25);
  552.                 repeat
  553.                    readln(S);
  554.                    S := Upper( S );
  555.                    Writeln( S );
  556.                 until S = 'QUIT';
  557.                 window(1,1,80,25);
  558.  
  559.              END (* Xupper *) .
  560. 
  561.                                 WAIT
  562.  
  563.  
  564. Declaration: Procedure Wait ( NumberOfSeconds : Integer );
  565.  
  566. Purpose:     Delays processing for the number of seconds specified 
  567.              by NumberOfSeconds or until a key press.  If the key 
  568.              pressed was the Home key, processing halts until 
  569.              another key press.
  570.  
  571. Example:     Display 'steps' with 1-second intervals.
  572.  
  573.              (*$IBoDecl *)
  574.              (*$ITimer  *)
  575.              (*$ICenter *)
  576.              (*$IPutStr *)
  577.              (*$IWait   *)
  578.        
  579.              BEGIN
  580.          
  581.                 ClrScr;
  582.                 PutStr ( h, 'Press a key for speed, home for hold',
  583.                          1, 25, 7 );
  584.                 for i := 1 to 24 do
  585.                 begin
  586.                    str (i, s);
  587.                    PutStr ( h,Center (S, 10,'-'), 1+(i-1)*3, i, 14 );
  588.                    wait(1);
  589.                 end
  590.  
  591.              END (* Xwait *) .
  592. 
  593.                                  WORD
  594.  
  595.  
  596.  
  597. Declaration: Function Word ( S : AnyString;
  598.                              N : Integer ) : AnyString;
  599.  
  600.  
  601. Purpose:     Returns word N of S.
  602.  
  603.  
  604.              Notes:
  605.  
  606.              1.  A word is any blank-delimited sequence of
  607.                  characters or a string of nonblank characters.
  608.  
  609.  
  610. Example:     Extract a word from a string.
  611.  
  612.  
  613.              Given:  S := 'The Lone Ranger's friend is Tonto.';
  614.  
  615.              Then:   T := Word ( S, 6 );
  616.  
  617.              Yields: T := 'Tonto.';
  618.  
  619.  
  620.              Note:
  621.  
  622.              1.  For a working routine of Word and other word
  623.                  functions, see the example for Words.
  624. 
  625.                                 WORDIND
  626.  
  627.  
  628.  
  629. Declaration: Function WordInd ( S : AnyString;
  630.                                 N : Integer ) : Integer;
  631.  
  632.  
  633. Purpose:     Returns the string position of word N in S.
  634.  
  635.  
  636.              Notes:
  637.  
  638.              1.  A word is any blank-delimited sequence of
  639.                  characters or a string of nonblank characters.
  640.  
  641.  
  642. Example:     Find the starting position of a word in a string.
  643.  
  644.  
  645.              Given:  S := 'These are the times that try our souls.';
  646.  
  647.              Then:   i := WordInd ( S, 4 );
  648.  
  649.              Yields: i := 15;  { Starting position of 'times' }
  650.  
  651.  
  652.              Note:
  653.  
  654.              1.  See Words below for a working routine using
  655.                  WordInd and the other word functions.
  656. 
  657.                                  WORDS
  658.  
  659.  
  660.  
  661. Declaration: Function Words ( S : AnyString ) : Integer;
  662.  
  663.  
  664. Purpose:     Returns the number of words in S.
  665.  
  666.  
  667.              Notes:
  668.  
  669.              1.  A word is any blank-delimited sequence of
  670.                  characters or a string of nonblank characters.
  671.              2.  The string 'Turbo Pascal' has 2 words.
  672.  
  673.  
  674. Example:     Analyze and optionally modify user input until
  675.              user types 'Q' or 'q'.
  676.  
  677.              (*$IBoDecl *)
  678.              (*$IStrip  *)
  679.              (*$ICenter *)
  680.              (*$IRword  *)
  681.              (*$IWord   *)
  682.              (*$IWords  *)
  683.              (*$IWordInd*)
  684.              (*$ISpace  *)
  685.  
  686.              var
  687.                 Ts : AnyString;
  688.                 j  : Integer;
  689.  
  690.              BEGIN
  691.                 ClrScr;
  692.                 Write( Center ( 'Type a message for analysis.'+
  693.                                 ' Q to quit.',80,' '));
  694.                 Write( Center ( '''n , string'' replaces word' +  
  695.                                 ' n of previous message'+
  696.                                 ' with ''string''',80,' ') );
  697.                 window (1,3,80,25);
  698. .E
  699.                 repeat
  700.                    readln( S );
  701.                    S := space(S);
  702.                    if Length(S) > 0 then
  703.                    begin
  704.                       val ( word(S,1), i, ecode );
  705.                       if (ecode = 0) and (word(S,2) = ',') then
  706.                       begin
  707.                          j  := WordInd (S, 3);
  708.                          Ts := rword ( Ts , i, 
  709.                               copy ( S, j, Length(S)-j+1) );
  710.                          Writeln ( Ts );
  711.                       end
  712.                       else
  713.                       begin
  714.                          Ts := S;
  715.                          Writeln ( S );
  716.                          i := 1 + Random(Words(Ts));
  717.                       end;
  718.                       GotoXY( WordInd(Ts,i), WhereY );
  719.                       writeln( #004 );
  720.                       Writeln( 'There are ',words(Ts),
  721.                                ' words in your message.');
  722.                       Writeln('There are ',length(word(Ts,i)),
  723.                               ' characters in word ',i);
  724.                    end (*  Length > 0 *);
  725.                 until (S = 'Q') or (S = 'q');
  726.                 window (1,1,80,25);
  727.  
  728.              END (*  Xwords *).
  729. .E
  730.  
  731.  
  732.